<template>
<div class="wrap">
    <el-form ref="form" :model="form" label-width="80px" :rules="rules">
        <el-form-item label="账号" prop="name">
            <el-input v-model="form.name" placeholder="请输入账号"></el-input>
        </el-form-item>
         <el-form-item label="密码" prop="pwd">
            <el-input v-model="form.pwd" placeholder="请输入密码" show-password></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">立即登陆</el-button>
        </el-form-item>
        </el-form>
</div>
    
</template>

<script>
export default {
    data() {
      return {
        form: {
          name: '',
          pwd:''
        },
        rules:{
            name:[
                { required: true,message: '请输入账号', trigger: 'blur' },
                 { min: 2, max:12, message: '长度在 2 到 12 个字符', trigger: 'blur' }
            ],
            pwd:[
                { required: true,message: '请输入密码', trigger: 'blur' },
                 { min: 3, max:12, message: '长度在 3 到 12 个字符', trigger: 'blur' }
            ]
        }
      }
    },
    methods: {
      onSubmit() {
        this.$http.post("/login",{name:this.form.name,pwd:this.form.pwd}).then(res => {
          if(res.data.asg.asg == "成功"){
            localStorage.setItem("id",res.data.asg.id);
            this.$router.push({path:"/home"})
          }else{
            alert(res.data.asg)
          }
        })
      }
    }
}
</script>

<style>

</style>
